<?php if (isset($lastChangesList) && !empty($lastChangesList)): ?>
	<div class="listing">
		<h3>Posledné vykonané zmeny</h3>
		<table class="list">
			<thead>
				<tr>
					<th class="col50"><?php echo 'Typ záznamu';?></th>
					<th class="identifier"><?php echo 'ID';?></th>
					<th class="col100"><?php echo 'Pôvodné hodnoty';?></th>
					<th class="col100"><?php echo 'Nové hodnoty';?></th>
					<th class="col50"><?php echo 'Dátum a čas';?></th>
					<?php if ($showChangedBy): ?>
						<th class="col100"><?php echo 'Zmenil';?></th>
					<?php endif; ?>
				</tr>
			</thead>
			<tbody>
				<?php foreach ($lastChangesList as $lastChange): ?>
				<?php $oldDiff = unserialize($lastChange['ChangeLog']['old_diff']); ?>
				<?php $newDiff = unserialize($lastChange['ChangeLog']['new_diff']); ?>
				<?php if (!empty($oldDiff) || !empty($newDiff)): ?>
					<tr>
						<td>
							<?php echo htmlspecialchars(AppModel::getItemType($lastChange['ChangeLog']['table'])); ?>
						</td>
						<td class="number">
							<?php 
								$controller = strtolower($lastChange['ChangeLog']['model']);
								if (isset($userPermissions[$controller]['edit'])) {
									echo $this->Html->link($lastChange['ChangeLog']['item_id'], array('controller' => $controller,'action' => 'edit', $lastChange['ChangeLog']['item_id']));
								} else {
									echo $lastChange['ChangeLog']['item_id'];
								}
							?>
						</td>
						<td class="red">
							<?php
								foreach ($oldDiff as $field => $value) {
									$model = new $lastChange['ChangeLog']['model']();
									$fieldName = $model->getFieldName($field);
									if ($fieldName) {
										echo htmlspecialchars($fieldName . ': ' . $model->getFieldValue($field, $value)) . '<br />';
									}
								}
							?>
						</td>
						<td class="green">
							<?php

								foreach ($newDiff as $field => $value) {
									$model = new $lastChange['ChangeLog']['model']();
									$fieldName = $model->getFieldName($field);
									if ($fieldName) {
										echo htmlspecialchars($fieldName . ': ' . $model->getFieldValue($field, $value)) . '<br />';
									}
								}
							?>
						</td>
						<td>
							<?php echo date('j. n. Y H:i:s', $lastChange['ChangeLog']['create_date']); ?>
						</td>
						<?php if ($showChangedBy): ?>
						<td>
							<?php echo htmlspecialchars($lastChange['CreatedBy']['full_name']); ?>
						</td>
						<?php endif; ?>
					</tr>
				<?php endif; ?>
				<?php endforeach; ?>
			</tbody>
		</table>
	</div>
<?php endif; ?>
